package com.example.server;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.ServerSocket;
import java.net.Socket;

public class Server1 {
	
	 private static ServerSocket serverSocket;
	 private static Socket clientSocket;
     private static InputStreamReader inputStreamReader;
	 private static BufferedReader bufferedReader;
	 private static String message;

	public static void main(String[] args) {
		 
        try {
            serverSocket = new ServerSocket(8005);
        } catch (IOException e) {
            System.out.println("Could not listen on port: 8001");
        }
 
        System.out.println("Server started. Listening to the port 8001");
 
        while (true) {
            try {
                clientSocket = serverSocket.accept();
                inputStreamReader =
                   new InputStreamReader(clientSocket.getInputStream());
                bufferedReader =
                   new BufferedReader(inputStreamReader);
                message = bufferedReader.readLine();
 
                System.out.println(message);
                inputStreamReader.close();
                clientSocket.close();
 
            } catch (IOException ex) {
                System.out.println("Problem in message reading");
            }
        }
	}
}
